package com.lechuang.user.util;

import lombok.extern.slf4j.Slf4j;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author: lc
 **/
@Slf4j
public class VerificationUtil {


      private static Pattern phone = Pattern.compile("^1[3|4|5|6|7|8|9][0-9]{9}$");
      private static Pattern loginPassword = Pattern.compile("(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])[a-zA-Z0-9]{8,16}");
    /**
     * "\^1\(\?:3\d|4[4-9]|5[0-35-9]|6[67]|7[013-8]|8\d|9\d)\d{8}$"
     * 验证手机号码
     * @param mobiles
     * @return
     */
    public static boolean isMobileNO(String mobiles){
        boolean flag = false;
        try{
            Matcher m = phone.matcher(mobiles);
            flag = m.matches();
        }catch(Exception e){
            log.error("请输入正确的手机号");
            flag = false;
        }
        return flag;
    }


    /**
     * 号码中间四位用*代替
     * @param mobile
     * @return
     */
    public static String  replaceMobile(String mobile){
        try{
            mobile = mobile.replaceAll("(\\d{3})\\d{4}(\\d{4})", "$1****$2");
        }catch(Exception e){
            log.error("请输入正确的手机号");
        }
        return mobile;
    }

    public static boolean checkPassword(String password){
        boolean flag = false;
        try{
            Matcher matcher = loginPassword.matcher(password);
            flag = matcher.matches();
        }catch(Exception e){
            log.error("密码必须由8-16位数字和大小写字母组成");
            flag = false;
        }
        return flag;
    }
}